﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace Royaume
{
    public partial class Attaque : System.Web.UI.Page
    {
        int Total;
        int vMilice;
        int vSoldat;
        int vCavalier;
        int vArcher;
        int vPretre;
        public SqlConnection myCn;
        protected SqlCommand myCmd;
        protected SqlDataReader myDr;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.reload();

                Total = 100 - vMilice - vSoldat - vCavalier - vArcher - vPretre;

            }
         // this.Label1.Text = "Vous pouvez ajouter " + Total + " unité(s)";
        }

        protected void btnEnvoyerArmee_Click(object sender, EventArgs e)
        {

        }

        private void reload()
        {
            this.getValue();
            vMilice = Convert.ToInt32(this.txtMilice.Value);
            vSoldat = Convert.ToInt32(this.txtSoldat.Value);
            vCavalier = Convert.ToInt32(this.txtCavalier.Value);
            vArcher = Convert.ToInt32(this.txtArcher.Value);
            vPretre = Convert.ToInt32(this.txtPretre.Value);

            this.sliMilice.Value = vMilice;
            this.sliSoldat.Value = vSoldat;
            this.sliCavalier.Value = vCavalier;
            this.sliArcher.Value = vArcher;
            this.sliPretre.Value = vPretre;

            this.lblMilice.Text = vMilice.ToString();
            this.lblCavalier.Text = vCavalier.ToString();
            this.lblSoldat.Text = vSoldat.ToString();
            this.lblArcher.Text = vArcher.ToString();
            this.lblPretre.Text = vPretre.ToString();
            //this.sliArcher.Attributes.Add("tBox", "ctl00$HolderContent$txtArcher");
           // this.sliSoldat.Attributes.Add("tBox", "ctl00$HolderContent$txtSoldat");
           // this.sliCavalier.Attributes.Add("tBox", "ctl00$HolderContent$txtCavalier");
           // this.sliMilice.Attributes.Add("tBox", "ctl00$HolderContent$txtMilice");

        }

        private void getValue()
        {
            this.myCn = Connect.getconnectionstringG();
            this.myCn.Open();
            this.myCmd = new SqlCommand("spAfficherArmee", this.myCn);
            this.myCmd.CommandType = CommandType.StoredProcedure;
            myCmd.Parameters.Add("@FkMembre", SqlDbType.Int).Value = 1;

            myDr = myCmd.ExecuteReader();

            while (myDr.Read())
            {
                this.txtMilice.Value = myDr[0].ToString();
                this.txtSoldat.Value = myDr[1].ToString();
                this.txtCavalier.Value = myDr[2].ToString();
                this.txtArcher.Value = myDr[3].ToString();
                this.txtPretre.Value = myDr[4].ToString();

                this.sliMilice.Max = Convert.ToInt32(myDr[0].ToString());
                this.sliSoldat.Max = Convert.ToInt32(myDr[1].ToString());
                this.sliCavalier.Max = Convert.ToInt32(myDr[2].ToString());
                this.sliArcher.Max = Convert.ToInt32(myDr[3].ToString());
                this.sliPretre.Max = Convert.ToInt32(myDr[4].ToString());
            }
            this.myCn.Close();
        }
    }
}